package com.web.spider;

import com.alibaba.fastjson.JSON;
import com.web.spider.util.HttpCrawler;
import com.web.spider.util.HttpUtil;
import com.web.spider.util.HttpUtils;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author chencl
 * @Date 2019/8/29 15:45
 * @Version: 1.0
 * @Description
 */
public class Test {
	public static void main(String[] args) {
		HttpCrawler httpCrawler = new HttpCrawler();
		String refer = "https://www.lagou.com/jobs/list_Java?px=default&city=%E9%87%8D%E5%BA%86";
		String url = "https://www.lagou.com/jobs/list_Java?px=default&city=%E9%87%8D%E5%BA%86";
		Map<String, String> header = new HashMap<>(2);
		header.put("refer", refer);
		header.put("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36");
		header.put("Host", "www.lagou.com");
		header.put("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
		header.put("Accept-Encoding", "gzip, deflate, br");
		header.put("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8,zh-TW;q=0.7");

		//String result = HttpUtils.get(url, header, null);
		String result = httpCrawler.get(url, header, null);
		System.out.println(result);

		header.put("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
		header.put("Origin", "https://www.lagou.com");
		header.put("Accept", "application/json, text/javascript, */*; q=0.01");

		Map<String, String> params = new HashMap<>(3);
		params.put("first", "true");
		params.put("pn", "1");
		params.put("kd", "Java");

		url = "https://www.lagou.com/jobs/positionAjax.json?px=default&city=%E9%87%8D%E5%BA%86&needAddtionalResult=false";
		//result = HttpUtils.post(url, header, JSON.toJSONString(params));
		result = httpCrawler.postForm(url, header, params);
		System.out.println(result);

	}
}
